﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;
using System.Data;

namespace jmwqz
{
    public partial class jifencenter : System.Web.UI.Page
    {
        private Maticsoft.BLL.tb_userdata buser = new Maticsoft.BLL.tb_userdata();
        private Maticsoft.Model.tb_userdata muser = null;

        private Maticsoft.BLL.tb_item bitem = new Maticsoft.BLL.tb_item();
        private Maticsoft.Model.tb_item mitem = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    string openid = MyCommFun.RequestParam("openid");

                    if (string.IsNullOrEmpty(openid))
                    {
                        if (Session["openid"] != null)
                        {
                            openid = Session["openid"].ToString();
                        }

                    }

                    if (!Page.IsPostBack)
                    {
                        List<Maticsoft.Model.tb_userdata> datas = buser.GetModelList(" wxid = '" + openid + "'");
                        if (datas == null || datas.Count == 0)
                        {
                            Response.Redirect("error.aspx");
                        }
                        else
                        {
                            muser = datas[0];
                        }


                        List<Maticsoft.Model.tb_item> items = bitem.GetModelList(" is_sale = 1 and expire_date > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' ");
                        if (items == null || items.Count == 0)
                        {

                        }
                        else
                        {
                            mitem = items[0];
                        }


                        Session["openid"] = openid;
                        Session["userid"] = muser == null ? 0 : muser.id;
                        Session["itemid"] = mitem == null ? 0 : mitem.id;
                        Session.Timeout = 5 * 60;
                    }
                }

            }
            catch
            {
                //Response.Redirect("http://www.jmvqz.cn/index12.php?page2=jifencenter");
            }
        }

        public string GetNickName()
        {
            if (muser != null)
            {
                return muser.realname; 
            }
            return "";
        }

        public string GetHeadImg()
        {
            if (muser != null)
            {
                return muser.imgurl;
            }
            return "";
        }
        //nhbcyz123.w48.mc-test.com
        //www.jmvqz.cn
        public string GetGzDate()
        {
            if (muser != null)
            {
                return muser.gz_time.ToString("yyyy-MM-dd hh:mm");
            }
            return "";
        }

        public string GetTj_num()
        {
            if (muser != null)
            {
                return muser.tj_num.ToString();
            }
            return "";
        }

        public string GetJifen()
        {
            if (muser != null)
            {
                return (muser.jifen + muser.freezejifen).ToString();
            }
            return "";
        }

        public string GetGood_Name()
        {
            if (mitem != null)
            {
                return mitem.name;
            }
            return "";
        }

        public string GetGood_Img()
        {
            if (mitem != null)
            {
                return mitem.img_orgin;
            }
            return "";
        }


        public string GetGood_Cost()
        {
            if (mitem != null)
            {
                return mitem.cost.ToString();
            }
            return "";
        }

        public string GetGood_Price()
        {
            if (mitem != null)
            {
                return mitem.price.ToString();
            }
            return "";
        }

        public string GetGood_ExpireDate()
        {
            if (mitem != null)
            {
                return mitem.expire_date.ToString("yyyy-MM-dd hh:mm");
            }
            return "";
        }

        public string GetGood_Stock()
        {
            if (mitem != null)
            {
                return mitem.stock.ToString();
            }
            return "";
        }
    }
}